package com.nmc.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.commons.AjaxHelper;
import com.metaparadigm.jsonrpc.JSONRPCBridge;
import com.nmc.AppUtils;
import com.nmc.core.manager.EmployeeManager;
import com.nmc.core.manager.WardManager;
import com.nmc.core.manager.ZoneManager;
import com.nmc.model.Employee;
import com.nmc.model.Role;
import com.opensymphony.xwork2.ActionSupport;

public class EmployeeAction extends ActionSupport implements ServletRequestAware {

	private WardManager wardManager;
	
	private EmployeeManager employeeManager;
	public EmployeeManager getEmployeeManager() {
		return employeeManager;
	}



	public void setEmployeeManager(EmployeeManager employeeManager) {
		this.employeeManager = employeeManager;
	}

	private ZoneManager zoneManager;
	private List zoneList;	
	private List wardList;	
	HttpServletRequest request;
	private boolean resultPage;
	private String searchTxt;
	private List roleList = null;
	
	

	private String zoneId;
	public Employee getEmployee() {
		return employee;
	}



	public void setEmployee(Employee employee) {
		
		  System.out.println("In Side setEmployee");
	        
		this.employee = employee;
	}

	private String wardId;
	 private List<Employee> empList = null;
	 

	
	 Employee employee;
	
	public String viewEmployee() throws Exception
    {
		/*JSONRPCBridge json_bridge = null;
		json_bridge = (JSONRPCBridge) request.getSession().getAttribute("JSONRPCBridge");
		if (json_bridge == null) {
			json_bridge = new JSONRPCBridge();
			request.getSession().setAttribute("JSONRPCBridge", json_bridge);
		}
		json_bridge.registerObject("getZoneList", new AjaxHelper(request.getSession().getServletContext()));*/

		empList = new ArrayList<Employee>();
        empList = employeeManager.getEmployeeList();
        
        System.out.println("In Side view Employee Action");
        
        
        return this.SUCCESS;
    }
	
	

	public List getRoleList() {
		
		System.out.println("In Side getRoleList  .......");
		
		return AppUtils.getRoleList();
	}

	public void setRoleList(List roles) {
		this.roleList = roles;
	}
	
	/**
     * @return Returns the batchList.
     */
    public List getEmpList()
    {
    	
    	 /*Employee employee = new Employee();
         employee.setEmpId("101");
         employee.setName("Ram Kumar");
         
         Employee employee1 = new Employee();
         employee1.setEmpId("101");
         employee1.setName("Ram Kumar");
         batchList = new ArrayList();
         
         batchList.add(employee);
         batchList.add(employee1);*/
    	
    	System.out.println("In Side getEmpList  .......");
    	//empList = employeeManager.getEmployeeList();
    	System.out.println("In Side getEmpList  ......."+ empList.size());    
    	return empList;
        //return this.batchList;
    }
	
    /**
     * @return Returns the batchList.
     */
    public String showAddEmployee()
    {
    	 System.out.println("In Side showAddEmployee  .......");
    	 return this.SUCCESS;
    }
 
    public String addEmployee()
    {
    	
    	 System.out.println("In Side view Employee Action" + employee.getEmpId());
   	  System.out.println("In Side view Employee Action" + employee.getEmpName());
   	  System.out.println("In Side view Employee Action" + employee.getEmpPhone());
   	  
   	 System.out.println("In Side view Employee Action" + employee.getRoleId());
   	  
   	  
    	// System.out.println("In Side addEmployee  .......");
    	 //System.out.println("In Side addEmployee  .......");
    	// Employee employee = new Employee();
    	// employee.setEmpName("Test User");
    	// employee.setEmpPhone("12343444");
    	 employeeManager.createEmployee(employee);
    	 
    	 
    	 // System.out.println("In Side view Employee Action" + employee.getEmpId());
    	 // System.out.println("In Side view Employee Action" + employee.getEmpName());
    	  //System.out.println("In Side view Employee Action" + employee.getEmpPhone());
    	 return this.SUCCESS;
    	 
    	 
    }
    
    
	public String zoneOffices()
	{
		return this.SUCCESS;
	}
	
	/**
	 * @return the searchTxt
	 */
	public String getSearchTxt() {
		return searchTxt;
	}

	/**
	 * @param searchTxt the searchTxt to set
	 */
	public void setSearchTxt(String searchTxt) {
		this.searchTxt = searchTxt;
	}

	/**
	 * @return the zoneId
	 */
	public String getZoneId() {
		return zoneId;
	}

	/**
	 * @param zoneId the zoneId to set
	 */
	public void setZoneId(String zoneId) {
		this.zoneId = zoneId;
	}

	/**
	 * @return the wardId
	 */
	public String getWardId() {
		return wardId;
	}

	/**
	 * @param wardId the wardId to set
	 */
	public void setWardId(String wardId) {
		this.wardId = wardId;
	}

	/**
	 * @param zoneList the zoneList to set
	 */
	public void setZoneList(List zoneList) {
		this.zoneList = zoneList;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}

	public String search() throws Exception {
			
			JSONRPCBridge json_bridge = null;
			json_bridge = (JSONRPCBridge) request.getSession().getAttribute("JSONRPCBridge");
			if (json_bridge == null) {
				json_bridge = new JSONRPCBridge();
				request.getSession().setAttribute("JSONRPCBridge", json_bridge);
			}
			json_bridge.registerObject("getZoneList", new AjaxHelper(request.getSession().getServletContext()));

			return SUCCESS;
		
	}
	public String searchTrack()
	{
		String flag = ERROR;
    		
        	
        	flag = SUCCESS;
        
    	
    	return flag;
	}
	/**
	 * @param wardManager the wardManager to set
	 */
	public void setWardManager(WardManager wardManager) {
		this.wardManager = wardManager;
	}

	/**
	 * @return the wardManager
	 */
	public WardManager getWardManager() {
		return wardManager;
	}

	/**
	 * @param zoneManager the zoneManager to set
	 */
	public void setZoneManager(ZoneManager zoneManager) {
		this.zoneManager = zoneManager;
	}

	/**
	 * @return the zoneManager
	 */
	public ZoneManager getZoneManager() {
		return zoneManager;
	}

	public List getZoneList()
	{
		zoneList = zoneManager.getZoneList();
		return zoneList;
	}

	/**
	 * @param wardList the wardList to set
	 */
	public void setWardList(List wardList) {
		this.wardList = wardList;
	}

	/**
	 * @return the wardList
	 */
	public List getWardList() {
		wardList = wardManager.getWardList();
		return wardList;
	}
	
}

